package me.kuku.test;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.ScriptResult;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import lombok.val;
import love.forte.simbot.bot.*;
import love.forte.simbot.component.mirai.configuration.MiraiBotVerifier;
import love.forte.simbot.core.bot.CoreBotManager;
import me.kuku.pojo.QqLoginPojo;
import me.kuku.pojo.Result;
import me.kuku.utils.MyUtils;
import me.kuku.utils.OkHttpUtils;
import me.kuku.utils.QqPasswordLoginUtils;
import me.kuku.utils.QqQrCodeLoginUtils;

import java.io.IOException;

public class PasswordE {

    private static final long appId = 716027609L;
    private static final int daId = 383;
    private static final long ptAid = 100497308L;
    public static void main(String[] args) throws IOException {
        if(true){
//            BotRegistrar botRegistrar = bootUtils.getBotRegistrar();
//
//            bootUtils.sendPrivate(this.getQqAdmin(),qq+"登录成功");
//
//            BotManager botManager = null;
//            BotVerifyInfo botVerifyInfo =new PairBotVerifyInfo.BasicBotVerifyInfo();
//            botManager.registerBot(botVerifyInfo);

            String a = QQlogin.pw();
            System.out.println(a);
//            val result = QqPasswordLoginUtils.login(2545737590l,
//                    "anhao445",appId,daId,"https://graph.qq.com/oauth2.0/login_jump");
            return;

        }

    }
    static Result a(Result<QqLoginPojo> result) throws IOException {
        val urlResult = QqQrCodeLoginUtils.authorize(result.getData(), ptAid, "state",
                "https://y.qq.com/portal/wx_redirect.html?login_type=1&surl=https://y.qq.com/"
        );

        if (urlResult.isFailure()) return Result.failure(urlResult.getMessage());
        val url = urlResult.getData();
        val code = MyUtils.regex("code=", "&", url);
        val response = OkHttpUtils.post(
                "https://u.y.qq.com/cgi-bin/musicu.fcg",
                OkHttpUtils.addJson("{\"comm\":{\"g_tk\":5381,\"platform\":\"yqq\",\"ct\":24,\"cv\":0},\"req\":{\"module\":\"QQConnectLogin.LoginServer\",\"method\":\"QQLogin\",\"param\":{\"code\":\"" + code + "\"}}}")
        );
        response.close();
        val cookie = OkHttpUtils.getCookie(response);
        val key = OkHttpUtils.getCookie(cookie, "qqmusic_key");
        System.out.println(key);
        return null;
    }
}
